import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: constantRoutes
}
const mutations = {
  setRoutes (state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  filterRoutes (context, menu) {
    const routes = []
    menu.forEach(key => {
      // 得到一个数组  可能有元素  也可能为空
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })
    context.commit('setRoutes', routes)
    // console.log(routes)
    return routes // 此处返回的结果给addRouters用
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
